﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FortuneHeaven.Admin.Common;
using FortuneHeavenBAL;
using FortuneHeavenCommon.Enum;

namespace FortuneHeaven.Admin.Pages.Statistic
{
    public partial class MemberList : FortuneHeaven.Admin.Common.PageBase
    {
        public override string PageID
        {
            get { return "F65"; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            lblDeptName.Text = "注册人数统计";
            this.usPager.PagerChanged += new Admin.Controls.TxtPagination.PagerChangeHandler(usPager_PagerChanged);
            if (!this.IsPostBack)
            {
                this.drpPagerSize.Items.Clear();
                this.drpPagerSize.Items.Add(new ListItem("每页10行", "10"));
                this.drpPagerSize.Items.Add(new ListItem("每页20行", "20"));
                this.drpPagerSize.Items.Add(new ListItem("每页50行", "50"));



                if (!string.IsNullOrEmpty(Request["pagesize"]))
                {
                    this.drpPagerSize.SelectedIndex = int.Parse(Request["pagesize"]);
                }
                else
                {
                    this.drpPagerSize.SelectedValue = "10";
                }
                if (!string.IsNullOrEmpty(Request["current"]))
                {
                    ResetList(int.Parse(Request["current"]));
                }
                else
                {
                    ResetList();
                }
                //this.lvNews.ItemCommand += new EventHandler<ListViewCommandEventArgs>(lvNews_ItemCommand);
            }
        }
        private void usPager_PagerChanged(object sender, int currentpage)
        {
            Refresh();
        }

        public void Refresh()
        {
            AccountsInfoBO gift = new AccountsInfoBO();
            lvNews.DataSource = gift.GetMemberUserInfor(this.usPager.CurrentPageIndex, int.Parse(this.drpPagerSize.SelectedValue), this.txtOrderID.Text, GetSelectInt());
            lvNews.DataBind();
        }

        protected void drpPagerSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            ResetList();
        }

        public void ResetList()
        {
            ResetList(1);
        }

        public void SearchValue(object sender, EventArgs e)
        {
            ResetList();
        }

        public string GetMemberName(object value)
        {
            int k = (int)value;
            return AttributeHelper.GetDescription((MemberType)k);
        }

        public int GetSelectInt()
        {
            int ret = -1;
            int.TryParse(this.drpMemberType.SelectedValue, out ret);
            return ret;
        }

        public void ResetList(int current)
        {
            AccountsInfoBO gift = new AccountsInfoBO();

            this.usPager.RecordCount = gift.GetMemberTotalSize(this.txtOrderID.Text, GetSelectInt());
            this.lbTotalMember.Text = this.usPager.RecordCount.ToString();
            this.usPager.PageSize = int.Parse(this.drpPagerSize.SelectedValue);
            this.usPager.Initial();
            this.usPager.CurrentPageIndex = current;
        }
    }
}